//------------------------------------------------------------------------
// Abstract: Define of class Memory
//
// Authoring: XiaoHanxiong
//
// Time: 2013.12.30
//
// Static test:
//
// Version history:
//		Ver_1.0 : 2013.12.30	XiaoHanxiong
//------------------------------------------------------------------------
#ifndef _Library_Memory_h_
#define _Library_Memory_h_

#include "Stdafx.h"

namespace Library
{
	// Type define
	typedef unsigned char Byte;

	class _LIBRARY Memory
	{
	public:
		Memory();
		~Memory();

	public:
		// Push a byte at back
		bool Push(Byte* p_value);
		// Inset a byte at front
		bool Insert(Byte* p_value);
		// Get the specified byte value by index
		bool Get(UINT index, Byte* result);
		// Set the specified byte value by index
		bool Set(UINT index, Byte* value);
		// Get the data size
		UINT Count();
	public:
		// Combine two memory object data together
		Memory operator + (Memory& memory);
		// Copy memory object data to anther
		Memory& operator = (Memory& memory);
	private:
		// Allocate memory
		bool Allocate(bool flag = true);
	private:

		// Point to the head address of memory
		byte* m_base;
		// Point to the address of memory which divide front and back
		byte* m_zero;
		// Point to the value begin address of memory
		byte* m_front;
		// Point to the value end address of memory
		byte* m_back;
		// The valid size of memory before zero
		unsigned int m_front_size;
		// The valid size of memory after zero
		unsigned int m_back_size;
		// The first allocated memory size
		static const unsigned int BASE_ALLOCATE = 5;
	};

}// _Library_

#endif